package com.web_bloks.utilities.client;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 * 
 * @author Jean-Lou Dupont
 *
 */
public class stringUtil {

	/*****************************************
	 * CONSTRUCTOR
	 *****************************************/

	/*****************************************
	 * CONFIGURATION
	 *****************************************/
	
	/*****************************************
	 * API
	 *****************************************/
	/**
	 * @return String
	 */
	public static String substitute(String source, HashMap<String, String> params) {
	
		String result = new String(source);
		
		Set<String> keys = params.keySet();
		Iterator<String> iter = keys.iterator();
		
		String key, value = null;
		int index = -1;
		while(iter.hasNext()) {
			key   = iter.next();
			value = params.get(key);
			index = source.indexOf( key );
			if (-1 == index) {
				continue;
			}
			result.replaceAll( key, value );
		}
		
		return result;
	}//
	
	
	/*****************************************
	 * HELPERS
	 *****************************************/

	
}//END